local yanzhu = fk.CreateSkill {
  name = "lvshi__yanzhu",
  tags = { "Turn" }
}

Fk:loadTranslationTable{
  ["lvshi__yanzhu"] = "宴诛",
  [":lvshi__yanzhu"] = "回合技，你可将一名已受伤角色的两张牌当【桃】对其使用，然后你可视为使用【落井下石】。",
  ["#lvshi__yanzhu-prompt"] = "宴诛：你可将一名角色的两张牌当【桃】对其使用",
  ["#lvshi__yanzhu-dying"] = "宴诛：你可将%src的两张牌当【桃】对其使用",
  ["#ls__yanzhu-choose"] = "请选择两张牌当【桃】对%src使用",
  ["#ls__yanzhu-rockfall"] = "你可视为使用【落井下石】",

  ["$lvshi__yanzhu1"] = "此宴菜肴寡淡，诸公皆欲食汝肉下酒！",
  ["$lvshi__yanzhu2"] = "宴饮岂可无戏，请君献头以博笑！",
}

yanzhu:addEffect("active", {
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt = "#lvshi__yanzhu-prompt",
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and #to_select:getCardIds("he") > 1 and to_select:isWounded()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(yanzhu.name) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = room:askToChooseCards(player, {
      target = target,
      min = 2,
      max = 2,
      flag = "he",
      skill_name = yanzhu.name,
      prompt = "#ls__yanzhu-choose:"..target.id
    })
    if #cards > 0 then
      room:useVirtualCard("peach", cards, player, target, yanzhu.name, true)
    end
    room:askToUseVirtualCard(player, {
      name = "lvshi__rockfall",
      skill_name = yanzhu.name,
      prompt = "#ls__yanzhu-rockfall",
    })
  end,
})

yanzhu:addEffect(fk.EnterDying, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yanzhu.name) and player:usedSkillTimes(yanzhu.name) == 0 and #target:getCardIds("he") > 1
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = yanzhu.name, prompt = "#lvshi__yanzhu-dying:"..target.id })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToChooseCards(player, {
      target = target,
      min = 2,
      max = 2,
      flag = "he",
      skill_name = yanzhu.name,
      prompt = "#ls__yanzhu-choose:"..target.id
    })
    if #cards > 0 then
      room:useVirtualCard("peach", cards, player, target, yanzhu.name, true)
    end
    if not table.find(room:getAlivePlayers(), function (p) return p.dying end) then
      room:askToUseVirtualCard(player, {
        name = "lvshi__rockfall",
        skill_name = yanzhu.name,
        prompt = "#ls__yanzhu-rockfall",
      })
    end
  end,
})

return yanzhu
